package com.jed.service;

import com.jed.dao.JiCaiShenHeDao;
import com.jed.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/jicaiApi")
public class JiCaiShenHeService {

	@Autowired
	private JiCaiShenHeDao jiCaiDao;

	@RequestMapping("/getJiCaiShenHeList")
	public List<Map<String, Object>> getJiCaiShenHeList() {
		List<Map<String, Object>> list = jiCaiDao.getJiCaiShenHeList();
		list = getList(list);
		return list;
	}

	@RequestMapping("/updateJiCaiShenHe")
	public int updateJiCaiShenHe(String id, int state, String reason) {
		int updateJiCaiShenHe = jiCaiDao.updateJiCaiShenHe(id, state, reason);
		return updateJiCaiShenHe;
	}

	/**
	 * 格式化集采list集合中的数据，将数字转为具体代表的含义
	 * 
	 * @param list
	 * @return list
	 */
	public List<Map<String, Object>> getList(List<Map<String, Object>> list) {
		for (Map<String, Object> map : list) {
			map.put("isjicai", ("1".equals(map.get("isjicai").toString())) ? "集采" : "非集采");
			map.put("tzhuangtai", ("1".equals(map.get("tzhuangtai").toString())) ? "已提交" : "未提交");
			map.put("shuxing", ("1".equals(map.get("shuxing").toString())) ? "预备库" : "必选库");
			map.put("ishetong", "1".equals(map.get("ishetong").toString())?"是":"否");
			map.put("yusuanjine", StringUtil.douToBig(map.get("yusuanjine")));
			map.put("isbixuanku", "1".equals(map.get("isbixuanku").toString())?"是":"否");
			map.put("isWeibao", "1".equals(map.get("isWeibao").toString())?"是":"否");
			String zijinlaiyuan = map.get("zijinlaiyuan").toString();
			switch (zijinlaiyuan) {
			case "1":
				zijinlaiyuan = "预算资金";
				break;
			case "2":
				zijinlaiyuan = "支付系统运维费";
				break;
			case "3":
				zijinlaiyuan = "征信查询补助";
				break;
			case "4":
			default:
				zijinlaiyuan = "其他";
				break;
			}
			map.put("zijinlaiyuan", zijinlaiyuan);
			String shenhezhuangtai = map.get("shenhezhuangtai").toString();
			switch (shenhezhuangtai) {
			case "1":
				shenhezhuangtai = "审核通过";
				break;
			case "2":
				shenhezhuangtai = "未审核";
				break;
			case "3":
			default:
				shenhezhuangtai = "审核未通过";
				break;
			}
			map.put("shenhezhuangtai", shenhezhuangtai);
		}
		return list;
	}

}
